from manimlib import *
from numpy import square
import numpy as np

class Test(Scene):
    #75cfb8
    #浅绿
    #bbdfc8
    #浅黄
    #f0e5d8
    #深黄
    #ffc478
    def construct(self):
        self.camera.frame.save_state()
        self.play(self.camera.frame.animate.scale(0.5).move_to([1,1.5,0]),time=0.01)
        l1=Line(color=BLACK,start=np.array([0,0,0]),end=np.array([0,3,0]))
        l2=Line(color=BLACK,start=np.array([0,0,0]),end=np.array([3,0,0]))

        y=ValueTracker(2)

        p1=Point(np.array([0,y.get_value(),0]),color='#ffc478').add_updater(lambda m:m.set_y(y.get_value()))
        p2=Point(np.array([1,0,0]),color='#ffc478').add_updater(lambda m:m.set_x(np.sqrt(5-y.get_value()*y.get_value())))
        p3=Point(np.array([1,2,0]),color='#ffc478').add_updater(lambda m:m.set_x((np.sqrt(5-y.get_value()*y.get_value())+2*y.get_value())/5).set_y((np.sqrt(5-y.get_value()*y.get_value())+2*y.get_value())/5*2))
        
        poly=Polygon(p1.get_center(),p2.get_center(),p3.get_center(),color='#75cfb8')
        poly.add_updater(lambda m:m.become(Polygon(p1.get_center(),p2.get_center(),p3.get_center(),color='#75cfb8')))

        angle=Angle(Line(p1.get_center(),p3.get_center()),Line(p2.get_center(),p3.get_center()),color='#75cfb8', radius=0.2,quadrant=(-1,-1),elbow=True)
        angle.add_updater(lambda m:m.become(Angle(Line(p1.get_center(),p3.get_center()),Line(p2.get_center(),p3.get_center()),color='#75cfb8', radius=0.2,quadrant=(-1,-1),elbow=True)))

        t=Text('一个直角三角形沿墙壁和地面滑动\n直角顶点的路径轨迹是什么形状?').scale(0.5).next_to(l2,DOWN)
        gj=TracedPath(p3.get_start,stroke_color='#ffc478')
        self.add(l1,l2,p1,p2,p3,poly,angle,t,gj)
        self.play(y.animate.set_value(0),rate_functions=running_start,time=0.05)
        self.wait(0.05)